let phone2 = document.querySelector("#phone2");
console.log(phone2);
let password_str = document.querySelector("#password_str");
console.log(password_str);
let auth_checkbox = document.querySelector(".auth_checkbox");
console.log(auth_checkbox);

let isUsername = false;
let isPassword = false;

phone2.onblur = function () {
  let reg =
    /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;

  if (reg.test(phone2.value)) {
    isUsername = true;
  } else {
    isUsername = false;
  }
};

password_str.onblur = function () {
  let reg = /^(?![a-zA-Z]+$)(?![0-9]+$)[A-Za-z0-9]{8,18}$/;
  if (reg.test(password_str.value)) {
    isPassword = true;
  } else {
    isPassword = false;
  }
};

function loginID() {
  if (isUsername && isPassword) {
    let username = phone2.value;
    let password = password_str.value;
    axios
      .get(loginAPI, {
        params: { username: username, password: password },
      })
      .then((res) => {
        let { data } = res;
        console.log(data);
        localStorage.setItem("username", data.data.username);
        localStorage.setItem("uid", data.data.id);
        localStorage.setItem("token", data.data.token);
        alert(data.msg);
        if (data.code == 1) {
          location.href = "index.html";
        }
      });
  }
}
